layui.define(function (exports) {
  let $ = layui.$

  // 监听hash 触发渲染
  function getHrefContent (hash) {
    if (hash.indexOf('?') > -1) {
      hash = hash.split('?')[0]
    }
    var content = '';
    hash = hash.split('#')[1]
    let href = 'res/pages/' + hash + '.html'
    $.ajax({
      url: href,
      type: 'get',
      dataType: 'html',
      async: false,
      success: function (data) {
        content = data;
      },
      error: function (xhr, textstatus, thrown) {
        content = getHrefContent('#home')
        return layer.msg(xhr.statusText + '，请稍后再试！');
      }
    });
    return content;
  }

  function doRoute () {
    let data = ''
    switch (window.location.hash) {
      case '':
        data = getHrefContent('#home')
        break
      default:
        data = getHrefContent(window.location.hash)
        break
    }
    $('.main-content').html(data)
  }
  window.onhashchange = function () {
    doRoute()
  }
  doRoute()

  exports('minRoute', {}); // 模块输出的核心，模块名必须和 use 时的模块名一致
});